import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import { fileURLToPath } from 'node:url'


// https://vitejs.dev/config/
export default defineConfig({
  base: '/static/',
  plugins: [
    vue(),
    vueJsx(),
    VueDevTools(),
    AutoImport({
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ['vue'],
      // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
      resolvers: [
        ElementPlusResolver()
      ]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    // 手动导入 el 组件，会自动添加对应的 css
    // 替换默认语言
    ElementPlus({
      defaultLocale: 'zh-cn',
      useSource: true
    })
  ],
  build: {
    outDir: '../ui/'  // 指定打包输出目录
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 5173,
    host: '0.0.0.0', // 绑定到所有可用的IP地址
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:9995',
        changeOrigin: true
        //rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
